package com.own.business.system.menu.business.entity.form;

import com.own.component.common.exception.BusinessSimpleException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * SystemMenuAdvancedSortForm
 *
 * @author chenxueli
 * @date 2024-05-14 13:19:00
 */
@Data
public class SystemMenuAdvancedSortForm implements Serializable {

    @Schema(title = "菜单列表")
    private List<Item> itemList;

    public void check() {
        if (itemList == null || itemList.isEmpty()) {
            throw new BusinessSimpleException("菜单列表不能为空");
        }
        itemList.forEach(Item::check);
    }

    @Data
    public static class Item implements Serializable {

        @Schema(title = "菜单id")
        private Long id;

        @Schema(title = "排序")
        private Integer sort;

        public void check() {
            if (id == null) {
                throw new BusinessSimpleException("菜单id不能为空");
            }
            if (sort == null) {
                throw new BusinessSimpleException("排序不能为空");
            }
        }

    }

}
